package com.hongsheng.util;

import com.hongsheng.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.sql.Date;
import java.text.SimpleDateFormat;

/**
 * TODO
 *
 * @author admin
 * @version 1.0
 * @date 2023/8/17 15:44
 */
public class OrderSqlProvider {
    public static String getOrder(@Param("order") Order order) {
        return new SQL() {{
            SELECT("o.*");
            FROM("tb_order o");
            JOIN("tb_customer c ON o.c_id = c.id");
            JOIN("tb_line l ON o.l_id = l.id");

            if (order.getOrderStatus() != null) {
                WHERE("o.order_status = #{order.orderStatus}");
            }
            if (order.getCreateTime() != null) {
                WHERE("DATE(o.create_time) = #{order.createTime}");
            }
            if (order.getLine().getStartAddress() != null && !order.getLine().getStartAddress().isEmpty()) {
                WHERE("l.start_address like #{order.line.startAddress}");
            }
            if (order.getCustomer().getName() != null && !order.getCustomer().getName().isEmpty()) {
                WHERE("c.name like #{order.customer.name}");
            }
            ORDER_BY("o.id");
        }}.toString();
}
}
